<template>
    <view class="taskDetails">
        <uni-nav-bar fixed left-icon="left" :title="title" @clickLeft="backHandle" class="unibarS">
            <block slot="right">
                <u-icon name="edit-pen" @click="editHandle()" color="#0C1019" size="26"></u-icon>
            </block>
        </uni-nav-bar>
        <!-- 主要内容 -->
        <view class="taskDetails-content">
            <!-- 任务信息 -->
            <view class="customer-info">
                <view v-if="detailsData.taskStatus == '1001'" class="customer-row-title">{{ detailsData.followupContent }}</view>
                <view v-else class="customer-row">
                    <view class="item">
                        <view>任务类型</view>
                        <view>跟进任务</view>
                    </view>
                    <view class="item">
                        <view>任务状态</view>
                        <view :style="getBgColor(detailsData.taskStatus)">{{ bus_task_status[detailsData.taskStatus] }}</view>
                    </view>
                    <!-- <view class="item">
                        <view>重要程度</view>
                        <view >---</view>
                    </view> -->
                </view>
            </view>
            <view class="info-c">
                <view>
                    <view class="item-title">任务信息</view>
                    <view class="item-content">
                        <view class="item-content-row">
                            <view>任务类型</view>
                            <view>跟进任务</view>
                        </view>
                        <view class="item-content-row">
                            <view>跟进内容</view>
                            <view>{{ detailsData.followupContent }}</view>
                        </view>
                        <view class="item-content-row">
                            <view>任务状态</view>
                            <view :style="getBgColor(detailsData.taskStatus)">{{ bus_task_status[detailsData.taskStatus] }}</view>
                        </view>
                        <view class="item-content-row">
                            <view>跟进时间</view>
                            <view>{{ detailsData.followupContent }}</view>
                        </view>
                        <!-- 状态不是未开始时显示 -->
                        <template>
                            <view class="item-content-row">
                                <view>关联业务</view>
                                <view>{{ detailsData.staffName }}</view>
                            </view>
                        </template>
                        <view class="item-content-row">
                            <view>客户名称</view>
                            <view class="link-box" @click="toCustomer()">{{ detailsData.customerName }}</view>
                        </view>
                        <view class="item-content-row">
                            <view>跟进人员</view>
                            <view>{{ detailsData.staffName }}</view>
                        </view>
                        <view class="item-content-row">
                            <view>任务提醒</view>
                            <view>{{ bus_followup_task[detailsData.reminderType] }}</view>
                        </view>
                        <view class="item-content-row">
                            <view>提醒方式</view>
                            <view>{{ bus_reminder_method[detailsData.reminderMethod] }}</view>
                        </view>
  
                        <view class="item-content-row">
                            <view>创建时间</view>
                            <view>{{ detailsData.createTime }}</view>
                        </view>
                        <view class="item-content-row">
                            <view>最后更新</view>
                            <view>{{ detailsData.updateTime }}</view>
                        </view>
                    </view>
                </view>
                <!-- <view>
                    <view class="item-title">处理信息</view>
                    <view class="item-content">
                        <view class="item-content-row">
                            <view>处理人员</view>
                            <view>---</view>
                        </view>
                        <view class="item-content-row">
                            <view>处理时间</view>
                            <view>---</view>
                        </view>
                        <view class="item-content-row">
                            <view>跟进记录</view>
                            <view>---</view>
                        </view>
                    </view>
                </view> -->
            </view>
        </view>
        <!-- 底部 -->
        <view class="bottom-box">
            <template>
                <view class="row-box" @click="editHandle()">
                    <u-icon name="edit-pen-fill" color="#0C1019" size="22"></u-icon>
                    <text>编辑任务</text>
                </view>
                <view @click="delHandle()" class="row-box">
                    <u-icon name="trash" color="#0C1019" size="22"></u-icon>
                    <text>删除</text>
                </view>
                <!-- <view @click="openPopup()" class="column-box">
                    <u-icon name="photo" color="#0C1019" size="22"></u-icon>
                    <text>更多操作</text>
                </view> -->
            </template>

        </view>
        <!-- 弹出框 -->
        <!-- <uni-popup ref="popup" type="bottom" background-color="#fff" border-radius="10px 10px 0 0">
            <view class="popup-box">
                <view class="popup-header">更多操作</view>
                <view class="popup-content">
                    <u-grid :border="false" col="4" @click="clickGrid">
                        <u-grid-item>
                            <view class="icon-box">
                                <u-icon name="plus-people-fill" color="#0C1019" :size="24"></u-icon>
                            </view>
                            <text class="grid-text">编辑任务</text>
                        </u-grid-item>
                        <u-grid-item>
                            <view class="icon-box">
                                <u-icon name="star" color="#0C1019" :size="24"></u-icon>
                            </view>
                            <text class="grid-text">删除任务</text>
                        </u-grid-item>
                    </u-grid>
                </view>
            </view>
        </uni-popup> -->
        <!--  -->
        <u-action-sheet :actions="list" title="任务处理" @close="close" @select="select" :show="show"></u-action-sheet>
    </view>
</template>

<script>
import { convertToDict } from '@/common/utils'
export default {
    data() {
        return {
            title: '任务详情',
            detailsData: {},
            userInfo: {
                name: '张三',
                phone: null,
                classType: null,   // 客户类型
                state: null, // 客户状态
                rate: null, // 客户星级
                source: null, // 客户来源
                // 业务员
                salesman: null,
                city: null, // 省市
                address: null, // 地址
                isFollow: true, // 是否跟进
                followTime: null,
                followContent: null, // 跟进内容
                remind: null, // 跟进提醒
                remindType: null, // 跟进提醒类型
            },
            list: [
                { name:'未签到完成', type: 1 },
                { name:'已签到完成', type: 2 }
            ],
            show:false,
        }
    },
    onLoad(options) {
        this.id = options.id

        // 提醒方式
        this.bus_reminder = JSON.parse(uni.getStorageSync('bus_reminder_method'))
        this.bus_reminder_method = convertToDict(this.bus_reminder)

        // 任务提醒
        this.bus_followup_t = JSON.parse(uni.getStorageSync('bus_followup_task'))
        this.bus_followup_task = convertToDict(this.bus_followup_t)

        this.bus_followup = JSON.parse(uni.getStorageSync('bus_followup_type'))
        this.bus_followup_type = convertToDict(this.bus_followup)
        // 跟进任务状态
        this.bus_task_status = convertToDict(JSON.parse(uni.getStorageSync('bus_task_status')))

        this.getDetails()
    },
    methods: {
        getDetails() {
			this.$http.get('/app/followup_record/' + this.id, {}).then(res => {
				if (res.code == 200) {
                    this.detailsData = res.data
                    this.title = res.data.followupContent
				} else {
					uni.$u.toast(res.msg)
				}
			})
		},
        toCustomer() {
            uni.navigateTo({
				url: '/pages/crm/customer/customerDetails?id=' + this.detailsData.customerId
			})
        },
        openPopup() {
            this.$refs.popup.open()
        },
        clickGrid(index) {
            console.log(index)
        },
        select(item) {
            uni.showModal({
                title: '提示',
                content: '确定要执行此操作吗？',
                success: function (res) {
                    if (res.confirm) {
                        console.log('用户点击确定');
                    } else if (res.cancel) {
                        console.log('用户点击取消');
                    }
                }
            });
        },
        // 编辑任务
        editHandle() {
            uni.redirectTo({
                url: '/pages/task/addTask?type=edit&id=' + this.detailsData.id
            });
        },
        // 删除
        delHandle() {
            let that = this
            uni.showModal({
                title: '提示',
                content: '确定要删除吗？',
                success: function (res) {
                    if (res.confirm) {
                        that.$http.del('/app/followup_record/' + that.id, {}).then(res => {
                            if (res.data.code == 200) {
                                uni.showToast({ title: '删除成功', duration: 1000 });
                                setTimeout(() => {
                                    uni.navigateBack()
                                }, 1000)
                            } else {
                                uni.$u.toast(res.msg)
                            }
                        })
                    } else if (res.cancel) {
                        console.log('用户点击取消');
                    }
                }
            });
        },
        getBgColor(state) {
            let color;
            switch (state) {
                case '1003':
                color = 'rgba(255, 0, 28, 1)';
                break;
                default:
                color = '';
            }
            return { color: color };
        },
        close() {
            this.show = false
        },
        backHandle() {
            uni.navigateBack()
        }
    }
}
</script>

<style lang="scss" scoped>
.unibarS {
    /deep/.uni-navbar__header {
        padding: 0 32rpx;
    }

    /deep/.uni-navbar__content {
        border-bottom: none !important;
        box-shadow: 0px 0px 4px rgba(136, 136, 136, 0.12);
    }

    .sub-btn {
        font-size: 32rpx;
        font-weight: 400;
        color: rgba(77, 172, 177, 1);
    }
}

.taskDetails {
    padding-bottom: 150rpx;
}

.taskDetails-content {
    margin: 20rpx 0;

    .customer-info {
        border-radius: 24rpx;
        background: rgba(255, 255, 255, 1);
        padding: 32rpx 0;

        .customer-row-title {
            padding: 0 32rpx;
            text-align: center;
            // 超出隐藏
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }

        .customer-row {
            display: flex;
            justify-content: space-between;
            text-align: center;

            .item {
                flex: 1;

                > :nth-child(1) {
                    font-size: 28rpx;
                    font-weight: 400;
                    color: rgba(103, 117, 133, 1);
                    margin-bottom: 8rpx;
                }

                > :nth-child(2) {
                    font-size: 28rpx;
                    font-weight: 500;
                    color: rgba(12, 16, 25, 1);
                }
            }
        }
    }

    .item-title {
        padding: 48rpx 32rpx 20rpx 32rpx;
        font-size: 32rpx;
        font-weight: 500;
        color: rgba(12, 16, 25, 1);
    }

    .item-content {
        background: rgba(255, 255, 255, 1);
        padding: 0 32rpx;
        border-radius: 24rpx;

        .item-content-row {
            display: flex;
            justify-content: space-between;
            padding: 26rpx 0;
            font-size: 28rpx;
            border-bottom: 2rpx solid rgba(240, 240, 240, 1);

            >view:nth-child(1) {
                font-weight: 400;
                font-weight: 500;
                color: rgba(12, 16, 25, 1);
                width: 140rpx;
            }

            >view:nth-child(2) {
                flex: 1;
                color: rgba(103, 117, 133, 1);
                // 超出隐藏显示省略号
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
                text-align: right;
            }

            .link-box {
                color: rgba(77, 172, 177, 1) !important;
            }
        }
    }
}

.bottom-box {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-around;
    background: rgba(255, 255, 255, 1);
    box-shadow: 0px 0px 12rpx rgba(0, 0, 0, 0.1);
    padding: 32rpx 0;

    .row-box {
        display: flex;
        align-items: center;
    }
    .column-box {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }
    text {
        font-size: 28rpx;
        font-weight: 500;
        color: rgba(12, 16, 25, 1);
        margin-left: 8rpx;
    }

}

.popup-box {
    padding: 32rpx 0;

    .popup-header {
        display: flex;
        justify-content: center;
        margin-bottom: 32rpx;
    }

    .icon-box {
        border-radius: 16rpx;
        background: #F2F2F2;
        width: 100rpx;
        height: 100rpx;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .grid-text {
        margin-top: 24rpx;
        margin-bottom: 32rpx;
        font-size: 28rpx;
    }
}
</style>